/*
 * @(#)LogicalException.java 1.0.0 27/05/2014 *
 * INTRODUCCION A APLICACIONES J2EE
 * Ing. Darwin Rodrigo Zottola Pareja
 * rodrigozeta@gmail.com - twitter @Monozeta
 */

package com.unt.javawebunt.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;

import com.unt.javawebunt.exception.DataAccessLayerException;

/**
 * Generic DAO Interface. Performs management methods to a particular entity.
 * 
 * @author rzottola
 * @version 1.0
 * @since 27/05/2014
 * 
 * @param <T>
 * @param <ID>
 */
public interface IGenericDAO<T, ID extends Serializable> {

	/**
	 * Performs a persistent insert or update of entity.
	 * 
	 * @param entity
	 * @return updated entity
	 */
	public ID save(T entity) throws DataAccessLayerException;

	public void saveOrUpdate(T entity) throws DataAccessLayerException;

	public void update(T entity) throws DataAccessLayerException;

	/**
	 * Deletes entity from persistent store.
	 * 
	 * @param entity
	 * @throws DataAccessLayerException
	 */
	public void delete(T entity) throws DataAccessLayerException;

	/**
	 * Search an instance by id. Return must be unique.
	 * 
	 * @param id
	 * @param lock
	 * @return
	 * @throws DataAccessLayerException
	 */
	public T findById(ID id, boolean lock) throws DataAccessLayerException;

	/**
	 * Returns all entities from table.
	 * 
	 * @return
	 */
	public List<T> findAll(Order order) throws DataAccessLayerException;

	/**
	 * Return all entities matching criteria
	 * 
	 * @param criterion
	 * @return
	 * @throws DataAccessLayerException
	 */
	public List<T> findByCriteria(Order order, Criterion... criterion)
			throws DataAccessLayerException;

	/**
	 * Return all entities matching criteria
	 * 
	 * @param criterion
	 * @return
	 * @throws DataAccessLayerException
	 */
	public List<T> findByCriteria(Order order, List<Criterion> critList)
			throws DataAccessLayerException;

	/**
	 * Return the number of all entities matching criteria
	 * 
	 * @param order
	 * @param criterionList
	 * @return
	 * @throws DataAccessLayerException
	 * <br>
	 * @author dzottola
	 * @since 26-05-2014 <br>
	 */
	public Long countByCriteria(Order order, Criterion... criterionList)
			throws DataAccessLayerException;

}
